$(document).ready(function () {
  $("#username").blur(function () {
    var username = $.trim($(this).val());
    if (username == "") {
      $("#usernameLabel").html("用户名不能为空！");
      return;
    }
    
    $("#usernameLabel").html("");
    $.get("/Practice/sys/user/checkUsername?username=" + username, function (data, status) {
      $("#usernameLabel").html(data);
    });
  });

  $("#email").blur(function () {
    var email = $.trim($(this).val());
    if (email == "") {
      $("#emailLabel").html("邮箱不能为空！");
      return;
    }
    if (!isEmail(email)) {
      $("#emailLabel").html("邮箱格式不正确！");
      return;
    }
    
    $("#emailLabel").html("");
    $.get("/Practice/sys/user/checkEmail?email=" + email, function (data, status) {
      $("#emailLabel").html(data);
    });
  });
  
  $("#password").blur(function () {
    var password = $.trim($(this).val());
    if (password == "") {
      $("#passwordLabel").html("密码不能为空！");
      return;
    }
    $("#passwordLabel").html("");
  });

  $("#confirmPassword").blur(function () {
    var password = $.trim($("#password").val());
    var confirmPassword = $.trim($(this).val());
    if (confirmPassword == "") {
      $("#confirmPasswordLabel").html("确认密码不能为空！");
      return;
    }
    if (password != confirmPassword) {
      $("#confirmPasswordLabel").html("两次输入密码不一致！");
      return;
    }
    $("#confirmPasswordLabel").html("");
  });
});